<template>
	<view>
		<view class="form-box">
			<view class="form-item">
				<view class="item-label">考试名称</view>
				<view class="item-input-right">
					<picker class="picker-scoreList" mode="selector" :range="ExamList" range-key="exam_name" value="index" @change="pickChange">
						<view>
							<text v-if="pickerIndex==-1" style="color: lightgray;">点击选择</text>
							{{ExamList[pickerIndex]!=undefined?ExamList[pickerIndex].exam_name:""}}
						</view>
					</picker>
				</view>
			</view>
			<button type="primary" @tap="btnQuery" style="margin-top: 20px;">查询</button>
		</view>
		<scoreResult  v-if="showResult" :scoreResultItem="scoreResultItem"></scoreResult>
	</view>
</template>

<script>
	import pageHeader from "../../components/pageHeader.vue";
	import scoreResult from "../../components/scoreResult.vue";
	import AppConfig from '../../config/AppConfig.js';
	import{mapGetters} from 'vuex';
	export default {
		name:"queryScore",
		data(){
			return{
				ExamList:[],
				pickerIndex:-1,
				exam_id:"",
				showResult:false,
				scoreResultItem:null
			}
		},
		computed:{
			...mapGetters(["s_id"])
		},
		onLoad:function(){
			uni.setNavigationBarTitle({
				title:"查询成绩"
			});
			uni.request({
				url:`${AppConfig.baseUrl}/Exam_info/getAllList`,
				success:res=>{
					this.ExamList=res.data.data;
				} 
			});
		},
		components:{
			pageHeader,scoreResult
		},
		methods:{
			pickChange(e){
				this.pickerIndex=e.detail.value;
				
			},
			//查询成绩
			btnQuery(){
				if(this.pickerIndex==-1){
					uni.showModal({
						title:"提示",
						content:'请选择考试名称',
						showCancel:false,
						confirmText:'确定'
					});
					
				}
				else{
					this.showResult=false;
					uni.showLoading({
						title:'正在查询'
					});
					uni.request({
						url:`${AppConfig.baseUrl}/Score_info/queryScore/${this.s_id}/${this.ExamList[this.pickerIndex].exam_id}`,
						success:res=>{
							if(res.data.status=="success"){
								this.scoreResultItem=res.data.data;
								this.showResult=true;
							}
							else{
								uni.showToast({
									icon:"none",
									title:res.data.msg
								});
							}
						},
						complete:function(){
							uni.hideLoading();
						}
					});
				}

			}
		}
	}
</script>

<style scoped>
.form-box{
	box-sizing: border-box;
	padding: 0px 20px;
}
.form-item{
	display: flex;
	flex-direction: row;
	height: 80px;
	margin-top: 10px;
	background-color: white;
}
.item-label{
	width: 170px;
	display: flex;
	height: 80px;
	justify-content: center;
	text-align: center;
	align-items: center;
}
.item-input-right{
	flex: 1;
	display: flex;
	align-items: center;
}
.item-input-right>input,.picker-scoreList{
	width: 100%;
	min-height: 80px;
}
.picker-scoreList{
	display: flex;
	align-items: center;
}

</style>
